package com.qianbao.qianbaobusiness.ui.support;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.androidbase.widget.recycleadpter.BaseRecycleViewAdapter;
import com.baseandroid.config.Global;
import com.qianbao.qianbaobusiness.BuildConfig;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.ui.invoice.EInvoiceListActivity;
import com.qianbao.qianbaobusiness.ui.support.customermanager.CustomerManagerActivity;
import com.qianbao.qianbaobusiness.ui.support.wechatprogram.WechatProgramActivty;
import com.qianbao.qianbaobusiness.ui.webview.SimpleWebViewActivity;
import com.tencent.stat.StatService;

/**
 * @author: Routee
 * @date 2018/6/15
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
class IncrementAdapter extends BaseRecycleViewAdapter<String> {

    public IncrementAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindBaseViewHolder(RecyclerView.ViewHolder holder, String item) {
        VH vh = (VH) holder;
        vh.mTv.setText(item);
        vh.mView.setVisibility(vh.getItemViewType() == 0 ? View.VISIBLE : View.GONE);
        vh.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (item) {
                    case "电子发票":
                        Intent invoice = new Intent(mContext, EInvoiceListActivity.class);
                        mContext.startActivity(invoice);
                        if (!BuildConfig.DEBUG) {
                            StatService.trackCustomEvent(Global.getContext(), "3_0_support_invoice");
                        }
                        break;
                    case "客户经理":
                        Intent manager = new Intent(mContext, CustomerManagerActivity.class);
                        mContext.startActivity(manager);
                        if (!BuildConfig.DEBUG) {
                            StatService.trackCustomEvent(Global.getContext(), "3_0_support_manager");
                        }
                        break;
                    case "零费率优惠":
                        if (!TextUtils.isEmpty(Global.getMerchantActivityBean().getUrl())) {
                            Intent intent = new Intent(mContext, SimpleWebViewActivity.class);
                            intent.putExtra("webview_url", Global.getMerchantActivityBean().getUrl());
                            mContext.startActivity(intent);
                        }
                        if (!BuildConfig.DEBUG) {
                            StatService.trackCustomEvent(Global.getContext(), "3_0_support_lingfeilv");
                        }
                        break;
                    case "微信小程序":
                        Intent wechatIntent = new Intent(mContext, WechatProgramActivty.class);
                        mContext.startActivity(wechatIntent);
                        if (!BuildConfig.DEBUG) {
                            StatService.trackCustomEvent(Global.getContext(), "3_0_support_wechat");
                        }
                        break;
                    default:
                        break;
                }
            }
        });
        switch (item) {
            case "电子发票":
                vh.mIv.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_invoice_support));
                break;
            case "客户经理":
                vh.mIv.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_manager_support));
                break;
            case "零费率优惠":
                vh.mIv.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_preferential_support));
                break;
            case "微信小程序":
                vh.mIv.setBackground(ContextCompat.getDrawable(mContext, R.drawable.icon_wx_support));
                break;
            default:
                break;
        }
    }

    @Override
    protected RecyclerView.ViewHolder onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_increment_support, null);
        return new VH(view);
    }

    @Override
    protected int getBaseItemViewType(int position) {
        return position % 2;
    }

    private class VH extends RecyclerView.ViewHolder {

        ImageView mIv;
        TextView  mTv;
        View      mView;

        public VH(View itemView) {
            super(itemView);
            mView = itemView.findViewById(R.id.view);
            mIv = itemView.findViewById(R.id.iv_icon);
            mTv = itemView.findViewById(R.id.tv_name);
        }
    }
}
